"""
验证添加客户_合法修改全部选项
"""
from selenium import webdriver
from selenium.webdriver.common.by import By
from time import sleep
from selenium.webdriver.support.select import Select

#打开浏览器
driver=webdriver.Chrome()
#打开悟空CRM
driver.get("http://192.168.1.83/crm/index.php?m=user&a=login")
driver.maximize_window()

#数据
username="wangmazi"
passwword="123456"
clientname="麻"
client_job_value="教育/培训"
massge_origin_value="电话营销"
zip_code="621114"
year_money_value="1-10万"
address_provinces_vlue="北京市"
address_city_vlue="市辖区"
address_district_vlue="东城区"
stree_massge_vlue="东街"
first_phone_name="王大麻子"
first_phone_chenghu_value="亲爱的坤"
first_phone_email_value="1554827380@qq.com"
first_phone_job_value="吃干饭"
first_phone_qq_value="1552636475"
first_phone_phonenumber_value="18281993022"
first_phone_beizhu_value="真爱粉"
addmassge_members_value="5--20人"
addmassge_beizhu_value="真爱粉"

#进入添加客户页面定位器
username_locator=(By.NAME,"name")
password_locator=(By.NAME,"password")
login_locator=(By.NAME,"submit")
client_locator=(By.XPATH,"/html/body/div[1]/div/div/div[2]/ul[1]/li[2]/a")
add_client_locator=(By.LINK_TEXT,"新建客户")


#添加客户定位器
owner_name_locator=(By.ID,"owner_name")
clientname_locator=(By.ID,"name")
client_job_locator=(By.ID,"industry")
massge_origin_loctor=(By.ID,"origin")
compan_hezi_locator=(By.ID,"ownership")
compan_guoqi_locator=(By.ID,"ownership1")
compan_mingying_locator=(By.ID,"ownership2")
zip_code_loctor=(By.ID,"zip_code")
year_monely_locator=(By.ID,"annual_revenue")
pingfen_one_locator=(By.ID,"rating")
pingfen_two_locator=(By.ID,"rating1")
pingfen_stree_locator=(By.ID,"rating2")
address_provinces_locator=(By.XPATH,"//*[@id='form1']/table/tbody/tr[6]/td[2]/select[1]")
address_city_locator=(By.XPATH,"//*[@id='form1']/table/tbody/tr[6]/td[2]/select[2]")
address_district_locator=(By.CSS_SELECTOR,"#form1 > table > tbody > tr:nth-child(6) > td:nth-child(2) > select:nth-child(4)")
stree_massge_locator=(By.XPATH,"//*[@id='form1']/table/tbody/tr[6]/td[2]/input")
#首要联系人定位器
first_phone_name_locator=(By.XPATH,"//*[@id='form1']/table/tbody/tr[8]/td[2]/input")
first_phone_chenghu_locator=(By.XPATH,"//*[@id='form1']/table/tbody/tr[8]/td[2]/input")
first_phone_email_locator=(By.XPATH,"//*[@id='form1']/table/tbody/tr[9]/td[2]/input")
first_phone_job_locator=(By.XPATH,"//*[@id='form1']/table/tbody/tr[9]/td[4]/input")
first_phone_qq_locator=(By.XPATH,"//*[@id='form1']/table/tbody/tr[10]/td[2]/input")
first_phone_phonenumber_locator=(By.XPATH,"//*[@id='form1']/table/tbody/tr[10]/td[4]/input")
first_phone_beizhu_locator=(By.XPATH,"//*[@id='form1']/table/tbody/tr[11]/td[2]/textarea")
#附加信息定位
addmassge_members_locator=(By.ID,"no_of_employees")
addmassge_beizhu_locator=(By.ID,"description")
save_locator=(By.CSS_SELECTOR,"#form1 > table > tfoot > tr > td > input:nth-child(1)")

#成功登录
driver.find_element(*username_locator).send_keys(username)
driver.find_element(*password_locator).send_keys(passwword)
driver.find_element(*login_locator).click()
sleep(2)

#点击客户，进入客户页面
driver.find_element(*client_locator).click()
#点击新建客户
driver.find_element(*add_client_locator).click()
#输入客户名称
driver.find_element(*clientname_locator).send_keys(clientname)
#输入客户行业
a=driver.find_element(*client_job_locator)
Select(a).select_by_value(client_job_value)
#客户信息来源
b=driver.find_element(*massge_origin_loctor)
Select(b).select_by_value(massge_origin_value)
#选择公司性质
driver.find_element(*compan_hezi_locator).click()
#填写邮编
driver.find_element(*zip_code_loctor).send_keys(zip_code)
#选择年营业额
c=driver.find_element(*year_monely_locator)
Select(c).select_by_value(year_money_value)
#选择评分
driver.find_element(*pingfen_one_locator).click()
sleep(2)
#选择客户联系地址
provinces=driver.find_element(*address_provinces_locator)
Select(provinces).select_by_value(address_provinces_vlue)
sleep(1)

city=driver.find_element(*address_city_locator)
Select(city).select_by_value(address_city_vlue)
sleep(1)

district=driver.find_element(*address_district_locator)
Select(district).select_by_value(address_district_vlue)
sleep(2)
#
driver.find_element(*stree_massge_locator).send_keys(stree_massge_vlue)
sleep(2)

#屏幕滑到最底部
js="window.scrollTo(0,document.body.scrollHeight)"
driver.execute_script(js)

#输入首要联系人信息
driver.find_element(*first_phone_name_locator).send_keys(first_phone_name)
#输入首要联系人称呼
driver.find_element(*first_phone_chenghu_locator).send_keys(first_phone_chenghu_value)
#输入首要联系人邮箱
driver.find_element(*first_phone_email_locator).send_keys(first_phone_email_value)
#输入首要联系人职位
driver.find_element(*first_phone_job_locator).send_keys(first_phone_job_value)
#输入首要联系人qq
driver.find_element(*first_phone_qq_locator).send_keys(first_phone_qq_value)
#输入首要联系人手机
driver.find_element(*first_phone_phonenumber_locator).send_keys(first_phone_phonenumber_value)
#输入首要联系人备注
driver.find_element(*first_phone_beizhu_locator).send_keys(first_phone_beizhu_value)
#选择员工数
members=driver.find_element(*addmassge_members_locator)
Select(members).select_by_value(addmassge_members_value)
#输入附加信息备注
driver.find_element(*addmassge_beizhu_locator).send_keys(*addmassge_beizhu_value)
#点击保存
driver.find_element(*save_locator).click()


sleep(3)
driver.quit()